package day5;

import java.util.Scanner;

public class StudentManager {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入学生人数：");
		int count = scanner.nextInt();
		Student[] students = new Student[count];
		for (int i = 0; i < students.length; i++) {
			System.out.println("请输入学生id：");
			int id = scanner.nextInt();
			System.out.println("请输入学生姓名：");
			String name = scanner.next();
			System.out.println("请输入学生班级：");
			String className = scanner.next();
			System.out.println("请输入学生年龄：");
			int age = scanner.nextInt();
			Student student = new Student(id, name, age, className);
			students[i] = student;
		}
		for (int i = 0; i < students.length; i++) {
			System.out.println(students[i]);
		}
		while (true) {
			System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
			System.out.println("欢迎使用学生查询系统");
			System.out.println("根据id查询：            1");
			System.out.println("根据姓名查询：         2");
			System.out.println("根据年龄查询：         3");
			System.out.println("根据班级查询：         4");
			System.out.println("退出系统：                0");
			System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
			System.out.println("请输入需要使用的功能代号");
			int num = scanner.nextInt();
			if (num == 0) {
				System.out.println("退出系统");
				return;
			}
			switch (num) {
			case 1://根据关键词查找
				boolean isSearchByIdFound = false;//false代表没找到
				System.out.println("请输入需查询的id：");
				int id = scanner.nextInt();
				for (int i = 0; i < students.length; i++) {
					if (id == students[i].getId()) {
						System.out.println(students[i]);
						isSearchByIdFound = true;
					}
				}
				if (isSearchByIdFound == false) {
					System.out.println("查找不到对应的信息");
				}
				break;
			case 2:
				boolean isSearchByNameFound = false;
				System.out.println("请输入查询的姓名：");
				String name = scanner.next();
				for (int i = 0; i < students.length; i++) {
					if (name.equals(students[i].getName())) {
						System.out.println(students[i]);
						isSearchByNameFound = true;
					}
				}
				if (isSearchByNameFound == false) {
					System.out.println("查找不到对应的信息");
				}
				break;
			case 3:
				boolean isSearchByAgeFound = false;
				System.out.println("请输入查询的年龄：");
				int age = scanner.nextInt();
				for (int i = 0; i < students.length; i++) {
					if (age == students[i].getAge()) {
						System.out.println(students[i]);
						isSearchByAgeFound = true;
					}
				}
				if (isSearchByAgeFound == false) {
					System.out.println("查找不到对应的信息");
				}
				break;
			case 4:
				boolean isSearchByClassNameFound = false;
				System.out.println("请输入查询的班级：");
				String className = scanner.next();
				for (int i = 0; i < students.length; i++) {
					if (className.equals(students[i].getClassName())) {
						System.out.println(students[i]);
						isSearchByClassNameFound = true;
					}
				}
				if (isSearchByClassNameFound == false) {
					System.out.println("查找不到相关信息");
				}
				break;
			default:
				break;
			}
		}
	}
}
